package com.xiechuang.util.response;

import com.xiechuang.constant.ResponseConstant;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description 响应类
 * @Author xiechuang
 * @Date 2021/10/31
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BaseResponse<T> {

    /**
     * 响应码
     */
    private Integer code;
    /**
     * 响应消息
     */
    private String message;
    /**
     * 响应数据
     */
    private T data;

    /**
     * 响应成功
     */
    public static <T> BaseResponse<T> success() {
        return new BaseResponse<>(ResponseConstant.SUCCESS_CODE, ResponseConstant.SUCCESS_MESSAGE, null);
    }

    /**
     * 响应成功
     */
    public static <T> BaseResponse<T> success(String message) {
        return new BaseResponse<>(ResponseConstant.SUCCESS_CODE, message, null);
    }

    /**
     * 响应成功
     */
    public static <T> BaseResponse<T> success(String message, T data) {
        return new BaseResponse<>(ResponseConstant.SUCCESS_CODE, message, data);
    }

    /**
     * 响应失败
     */
    public static <T> BaseResponse<T> fail() {
        return new BaseResponse<>(ResponseConstant.FAIL_CODE, ResponseConstant.FAIL_MESSAGE, null);
    }

    /**
     * 响应失败
     */
    public static <T> BaseResponse<T> fail(String message) {
        return new BaseResponse<>(ResponseConstant.FAIL_CODE, message, null);
    }

    /**
     * 响应失败
     */
    public static <T> BaseResponse<T> fail(String message, T data) {
        return new BaseResponse<>(ResponseConstant.FAIL_CODE, message, data);
    }

}
